/*
 *  Copyright 2019-2020 Zheng Jie
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package me.zhengjie.modules.biz.rest;

import me.zhengjie.annotation.Log;
import me.zhengjie.modules.biz.domain.HazardousChemicalsChangeRecord;
import me.zhengjie.modules.biz.service.HazardousChemicalsChangeRecordService;
import me.zhengjie.modules.biz.service.dto.HazardousChemicalsChangeRecordQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
 * @website https://eladmin.vip
 * @author Admin
 * @date 2023-03-09
 **/
@RestController
@RequiredArgsConstructor
@Api(tags = "hazardous-chemicals-change-record管理")
@RequestMapping("/api/hazardousChemicalsChangeRecord")
public class HazardousChemicalsChangeRecordController {

    private final HazardousChemicalsChangeRecordService hazardousChemicalsChangeRecordService;

    @Log("器材导出数据")
    @ApiOperation("器材导出数据")
    @GetMapping(value = "/exportEquipmentsChangeRecord")
//    @PreAuthorize("@el.check('hazardousChemicalsChangeRecord:list')")
    public void exportEquipmentsChangeRecord(HttpServletResponse response, HazardousChemicalsChangeRecordQueryCriteria criteria) throws IOException {
        hazardousChemicalsChangeRecordService.exportEquipmentsChangeRecord(hazardousChemicalsChangeRecordService.queryAll(criteria), response);
    }

    @Log("标准物质导出数据")
    @ApiOperation("标准物质导出数据")
    @GetMapping(value = "/exportMaterialsChangeRecord")
//    @PreAuthorize("@el.check('hazardousChemicalsChangeRecord:list')")
    public void exportMaterialsChangeRecord(HttpServletResponse response, HazardousChemicalsChangeRecordQueryCriteria criteria) throws IOException {
        hazardousChemicalsChangeRecordService.exportMaterialsChangeRecord(hazardousChemicalsChangeRecordService.queryAll(criteria), response);
    }

    @Log("化学试剂导出数据")
    @ApiOperation("化学试剂导出数据")
    @GetMapping(value = "/exportChemicalsChangeRecord")
//    @PreAuthorize("@el.check('hazardousChemicalsChangeRecord:list')")
    public void exportChemicalsChangeRecord(HttpServletResponse response, HazardousChemicalsChangeRecordQueryCriteria criteria) throws IOException {
        hazardousChemicalsChangeRecordService.exportChemicalsChangeRecord(hazardousChemicalsChangeRecordService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询hazardous-chemicals-change-record")
    @ApiOperation("查询hazardous-chemicals-change-record")
//    @PreAuthorize("@el.check('hazardousChemicalsChangeRecord:list')")
    public ResponseEntity<Object> queryHazardousChemicalsChangeRecord(HazardousChemicalsChangeRecordQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(hazardousChemicalsChangeRecordService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增hazardous-chemicals-change-record")
    @ApiOperation("新增hazardous-chemicals-change-record")
//    @PreAuthorize("@el.check('hazardousChemicalsChangeRecord:add')")
    public ResponseEntity<Object> createHazardousChemicalsChangeRecord(@Validated @RequestBody HazardousChemicalsChangeRecord resources){
        return new ResponseEntity<>(hazardousChemicalsChangeRecordService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改hazardous-chemicals-change-record")
    @ApiOperation("修改hazardous-chemicals-change-record")
//    @PreAuthorize("@el.check('hazardousChemicalsChangeRecord:edit')")
    public ResponseEntity<Object> updateHazardousChemicalsChangeRecord(@Validated @RequestBody HazardousChemicalsChangeRecord resources){
        hazardousChemicalsChangeRecordService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除hazardous-chemicals-change-record")
    @ApiOperation("删除hazardous-chemicals-change-record")
//    @PreAuthorize("@el.check('hazardousChemicalsChangeRecord:del')")
    public ResponseEntity<Object> deleteHazardousChemicalsChangeRecord(@RequestBody Integer[] ids) {
        hazardousChemicalsChangeRecordService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
